/** 
 * Copyright (C), 2010-2012, AIYOU Software Co.,Ltd. ALL RIGHTS RESERVED. 
 * File name:MidMessageUserServiceImp.java
 * Version:1.0
 * Date:Dec 7, 2011
 * Description: 
 * author:whh
 */
package com.tietiao.service.midmessageuser;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.tietiao.common.constants.LogConstants;
import com.tietiao.dao.MidMessageUserMapper;
import com.tietiao.dao.model.MidMessageUser;
import com.tietiao.dao.model.MidMessageUserCriteria;
import com.tietiao.service.syslog.SysLogService;
@Service
public class MidMessageUserServiceImp implements MidMessageUserService {
	@Resource
	private MidMessageUserMapper midMessageUserMapper;
	@Resource
	private SysLogService sysLogService;
	@Override
	public int deleteMidMessageUser(int messageId, int userId) {
		sysLogService.insertSysLog(LogConstants.OP_TYPE_DELETE, "发送消息", "删除消息:"+messageId);
		
		MidMessageUserCriteria midMessageUserCriteria = new MidMessageUserCriteria();
		MidMessageUserCriteria.Criteria criteria= midMessageUserCriteria.createCriteria();
		
		criteria.andUserIdEqualTo(userId);
		criteria.andMessageIdEqualTo(messageId);
		return midMessageUserMapper.deleteByExample(midMessageUserCriteria);
	}

	public int insertMidMessageUser(MidMessageUser sysMessage) {
		sysLogService.insertSysLog(LogConstants.OP_TYPE_INSERT, "发送消息", "给单个用户发送消息:"+sysMessage.getMessageId());
		return midMessageUserMapper.insert(sysMessage);
	}

	public int sendMessageToAll(int messageId) {
		sysLogService.insertSysLog(LogConstants.OP_TYPE_UPDATE, "发送消息", "批量发送消息,消息ID号："+messageId);
		return midMessageUserMapper.sendMessageToAll(messageId);
	}


	public int insertBatchMidd(int messageId, Integer[] receiveIds) {
		//midMessageUserMapper.insertBatchMidd(messageId,receiveIds);
		return 0;
	}
}
